# 基类object中提供的特殊方法及对应的运算符
#   特殊方法            运算符
# __add__()             +
# __sub_()              -
# __mul__()             *
# __truediv()           /
# __mod__()             %
# __pow__()             **
# __contains__()       in
# ......
# 定义一个计算器类Calculator,并重写特殊方法使+、-、*、/能够支持针对Calculator对象的运算
class Calculator(object):
    def __init__(self, number):  # 记录数值
        self.number = number

    def __add__(self, other):  # 重载运算符+
        return self.number + other

    def __sub__(self, other):  # 重载运算符—
        return self.number - other

    def __mul__(self, other):  # 重载运算符*
        return self.number * other

    def __truediv__(self, other):  # 重载运算符/
        return self.number / other

    def __mod__(self, other):  # 重载运算符%
        return self.number % other


# 对运算符进行重载后，自定义类Calculator也可以进行四则运算
calendar = Calculator(10)
print(calendar + 5)
print(calendar - 5)
print(calendar * 5)
print(calendar / 5)
print(calendar % 5)
